package smedi.ismedi.mobile.bff.controller.draft;

import com.smedi.ismedi.authority.starter.util.AuthorityUtil;
import com.smedi.ismedi.draft.api.dto.request.*;
import com.smedi.ismedi.draft.api.dto.response.DraftResponse;
import com.smedi.ismedi.draft.api.feign.RemoteDraftFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 草稿
 *
 * @author xienannan
 * @date 2021/08/28
 */
@FeignClient(name = "ismedi-draft")
@Api(tags = {"草稿"})
@RequestMapping(value = "/mobilebff/v1/draft")
@RestController
@AllArgsConstructor
public class DraftController {

    private final RemoteDraftFeignApi remoteDraftFeignApi;

    private final AuthorityUtil authorityUtil;

    /**
     * 新增 草稿
     *
     * @param draftCreateRequest 草稿 新增 请求
     * @return ResponseData<Long>
     */
    @ApiOperation(value = "草稿新增", nickname = "草稿新增")
    @PostMapping(value = "/create")
    ResponseData<Long> createDraft(@Validated @RequestBody DraftCreateRequest draftCreateRequest) {
        return remoteDraftFeignApi.createDraft(draftCreateRequest);
    }

    /**
     * 新增 草稿
     *
     * @param draftEditRequest 草稿 编辑 请求
     * @return ResponseData<Long>
     */
    @ApiOperation(value = "草稿编辑", nickname = "草稿编辑")
    @PostMapping(value = "/edit")
    ResponseData<Boolean> editDraft(@Validated @RequestBody DraftEditRequest draftEditRequest) {
        return remoteDraftFeignApi.editDraft(draftEditRequest);
    }

    /**
     * 删除 草稿
     *
     * @param draftRemoveRequest 草稿 删除 请求
     * @return ResponseData<DraftResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "删除 草稿")
    @PostMapping(value = "/remove")
    ResponseData<Boolean> removeDraft(@Validated @RequestBody DraftRemoveRequest draftRemoveRequest) {
        return remoteDraftFeignApi.removeDraft(draftRemoveRequest);
    }

    /**
     * 获取 草稿 单一
     *
     * @param draftOneRequest 草稿 单一 请求
     * @return ResponseData<DraftResponse>
     */
    @ApiOperation(value = "获取 草稿 单一", nickname = "获取 草稿 单一")
    @PostMapping(value = "/one")
    ResponseData<DraftResponse> getDraftOne(@Validated @RequestBody DraftOneRequest draftOneRequest) {
        return remoteDraftFeignApi.getDraftOne(draftOneRequest);
    }

    /**
     * 获取 草稿 分页
     *
     * @param draftPageRequest 草稿 分页 请求
     * @return ResponseData<DraftResponse>
     */
    @ApiOperation(value = "获取 草稿 分页", nickname = "获取 草稿 分页")
    @PostMapping(value = "/page")
    ResponseData<PaginationData<DraftResponse>> getDraftPage(@Validated @RequestBody DraftPageRequest draftPageRequest) {
        draftPageRequest.setByAuthenticationFilter(true);
        draftPageRequest.setCreatedUserId(authorityUtil.getPersonId());
        return remoteDraftFeignApi.getDraftPage(draftPageRequest);
    }
}

